//
//  HZNormalWebViewController.m
//  app
//
//  Created by 刘华舟 on 15/6/4.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZNormalWebViewController.h"
#import <WebKit/WebKit.h>

@interface HZNormalWebViewController()<UIWebViewDelegate, UIScrollViewDelegate>

@property (strong, nonatomic) WKWebView *webView;

@property (strong, nonatomic) UIActivityIndicatorView *activity;

@end

@implementation HZNormalWebViewController

- (void) viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 20, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-20)];
    //self.webView.UIDelegate = self;
    //self.webView.scrollView.delegate = self;
    
    [self.view addSubview:self.webView];
    
    self.activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    self.activity.center = self.webView.center;
    self.activity.hidesWhenStopped = YES;
    [self.view addSubview:self.activity];
    
    self.navigationController.navigationBar.hidden = NO;
    
    
    self.webURL = @"http://www.5yaoss.com";
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    
    if (self.webTitle.length) {
        self.title = self.webTitle;
    }else{
        self.title = @"";
    }
    
    //[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.webURL]]];
    
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"html"];
    NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    [self.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
    
    [self.view bringSubviewToFront:self.activity];
    [self.activity startAnimating];
}

#pragma mark 返回
- (void)backBtnOnClick{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 从新加载页面
- (void)refreshData{
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.webURL]]];
}
//
//#pragma mark UIWebViewDelegate
//- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
//    
//    return YES;
//}
//- (void)webViewDidStartLoad:(UIWebView *)webView{
//    [self.activity startAnimating];
//}
//- (void)webViewDidFinishLoad:(UIWebView *)webView{
//    [self.activity stopAnimating];
//}
//- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
//    [self.activity stopAnimating];
//}

@end
